// 创建仓库实例

import { createStore } from 'vuex'

const store = createStore({
  state() {
    // 写成函数的形式可以提供一些js逻辑
    return {
      count: 99,
    }
  },
  getters: {
    double(state) {
      return state.count * 2
    },
  },
  mutations: {
    addOne(state) {
      state.count++
    },
  },
  actions: {
    addOneAsync(context) {
      setTimeout(() => {
        context.commit('addOne')
      }, 1000)
    },
  },
})

export default store
